package com.zmzncs.lmtc.module.park.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.park.pojo.park_manager.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.zmzncs.lmtc.module.park.service.ParkManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 车场管理员表 前端控制器
 * </p>
 *
 * @author 高博文
 * @since 2020-12-09
 */
@Api(tags = {"车场管理员表"})
@RestController
@RequestMapping("/park/park-manager")
public class ParkManagerController {

    @Autowired
    private ParkManagerService parkManagerService;


    @ApiOperation(value = "新增车场管理员表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping("add")
    public Rest add(@RequestBody @Validated ParkManagerAddForm form){
        parkManagerService.add(form);

        return RestUtil.success();
    }

    @ApiOperation(value = "删除车场管理员表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(name = "id", value = "车场管理ID", required = true),
    })
    @PostMapping("delete")
    public Rest delete(@NotNull Long id){
        parkManagerService.delete(id);

        return RestUtil.success();
    }

    @ApiOperation(value = "更新车场管理员表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping("update")
    public Rest update(@RequestBody @Validated ParkManagerUpdateForm form){
        parkManagerService.update(form);

        return RestUtil.success();
    }

    @ApiOperation(value = "查询车场管理员表分页数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @GetMapping("page")
    public Rest<IPage<ParkManagerDTO>> page(@Valid ParkManagerSearchForm form){
        IPage<ParkManagerDTO> iPage = parkManagerService.page(form);

        return RestUtil.success(iPage);
    }

    @ApiOperation(value = "根据id查询车场管理员表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(name = "id", value = "车场管理ID", required = true),
    })
    @GetMapping("get-by-id")
    public Rest<ParkManagerInfoVO> getById(@NotNull Long id){
        ParkManagerDTO parkManagerDTO = parkManagerService.getById(id);

        return RestUtil.success(parkManagerDTO);
    }

    @ApiOperation(value = "根据手机号查询车场管理员表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(name = "mobilePhone", value = "车场管理ID", required = true),
    })
    @GetMapping("get-by-mobile")
    public Rest<ParkManagerDTO> getByMobile(@NotNull String mobilePhone){
        ParkManagerDTO parkManagerDTO = parkManagerService.getByMobile(mobilePhone);
        if (parkManagerDTO == null){
            return RestUtil.warning("未查询到车场主信息");
        }

        return RestUtil.success(parkManagerDTO);
    }

    @ApiOperation(value = "根据id删除车场管理员")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(name = "id", value = "车场管理ID", required = true),
    })
    @PostMapping("delete-by-id")
    public Rest deleteById(@NotNull Long id){
        parkManagerService.deleteByManagerId(id);

        return RestUtil.success();
    }




}
